package tech.aister.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 本来用来演示:
 *
 * @author success
 * @date 2025/3/3 15:52:56
 */
@RestController
@RequestMapping("ses")
public class SessionController {

    @GetMapping("add")
    public String add(String name, HttpServletRequest request){
        HttpSession session = request.getSession();
        session.setAttribute("name",name);
        return "session-ok";
    }

    @GetMapping("get")
    public String add(HttpServletRequest request){
        HttpSession session = request.getSession();
        String name = (String) session.getAttribute("name");
        return name;
    }

}
